/**
 * @Company:中享思途   
 * @Title:FrontAddressController.java 
 * @Author:IL Clown   
 * @Date:2020年8月24日 下午9:23:41     
 */
package com.situ.shopsystem.controller;

import java.io.Serializable;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.shopsystem.pojo.Address;
import com.situ.shopsystem.pojo.Area;
import com.situ.shopsystem.pojo.User;
import com.situ.shopsystem.service.AddressService;
import com.situ.shopsystem.service.AreaService;

/** 
 * @ClassName:FrontAddressController 
 * @Description:(这里用一句话描述这个类的作用) 
 * 
 *  
 *  
 *  
 *  shop/doAddress
 * shop/goAddress
 * shop/goAddAddress
 * shop/doDelete
 * shop/isDefault
 * shop/
 * shop/
 * shop/
 *  
 *  
 */
@Controller
@RequestMapping("/shop/")
public class FrontAddressController implements Serializable {
	private static final long serialVersionUID = 1L;
	@Autowired
	private AddressService addressService;
	@Autowired
	private AreaService areaService;

	@RequestMapping("goAddress")
	public String goAddress(Model model, HttpSession session) {
		User user = (User) session.getAttribute("user");
		List<Address> list = addressService.findAll(user.getRowId());
		model.addAttribute("addressList", list);
		return "shop/address";
	}

	@RequestMapping("doAddress")
	public String doAddress(Address address, HttpSession session) {
		addressService.save(address, session);
		return "redirect:goAddress";
	}

	@RequestMapping("goAddAddress")
	public String goAddAddress(Model model) {
		model.addAttribute("select1", areaService.findById("-1"));
		model.addAttribute("select2", areaService.findById("11"));
		model.addAttribute("select3", areaService.findById("1101"));
		return "shop/addAddress";
	}

	@ResponseBody
	@RequestMapping("findByParentCode")
	public List<Area> findByParentCode(String parentCode) {
		return areaService.findById(parentCode);
	}

	@RequestMapping("doDelete")
	public String doDelete(Long rowId) {
		addressService.delete(rowId);
		return "redirect:goAddress";
	}

	@RequestMapping("isDefault")
	public String isDefault(Long rowId,HttpSession session) {
		 addressService.updateDefault(rowId, session);
		
			return "redirect:goAddress";
	}

}
